// __PUBLIC__/js/page/cms/block/blocklist
require(['../../common'], function() {
  require(['block.blocklist'])
})

define('block.blocklist', [
  'jquery',
  'page/grid'
], function($, Grid) {
  'use strict';

  var $table = $('.table')
  var mygrid = new Grid($table)
  mygrid.init();

  function del(selected) {
    $.post(APP + '?app=cms&m=Block&a=delBlock', {
      ids: selected.id.join()
    })
      .done(function(data) {
        if (data == 1) {
          mygrid.del(selected.index)
        } else {
          alert('删除失败')
        }
      })
  }

  $table

  // 删除当前行
  .on('click', '.A_del', function(e) {
    e.preventDefault()
    if (confirm('确定删除已选择的内容')) {
      var current = mygrid.getCurrent(this)
      var selected = {
        id: [current.id],
        index: [current.index]
      }
      del(selected)
    }
  })

  // 删除选中行
  $('#J_del').click(function(e) {
    e.preventDefault()
    if (confirm('确定删除已选择的内容')) {
      var selected = mygrid.getSelected()
      if (!selected.count) {
        alert(lang.pleaseSelectAData)
        return
      }
      del(selected)
    }
  });

})
